package com.nulldev.util.other;

import com.nulldev.util.math.MathUtil;

public class BooleanUtil {

	public static String toBinary(final boolean value) {
		if (value) {
			return "1";
		}else {
			return "0";
		}
	}
	
	public static boolean fromBinary(final String value) {
		if (value.equals("1")) {
			return true;
		}else {
			return false;
		}
	}
	
	public static boolean fromBinary(final long value) {
		if (value == 1) {
			return true;
		}else {
			return false;
		}
	}

	public static boolean safeParse(final String string) {
		if (string == null) {
			return false;
		}
		if (string.equals("1") || string.equals("true") || string.equals("True") || 
				string.equals("Boolean.TRUE") || string.equals("true<newline>") || string.equals("YES") || string.equals("TRUE")) {
			return true;
		}else {
			return false;
		}
	}

	public static boolean random() {
		return (MathUtil.randInt(-100, 100) > 0);
	}
}
